package com.ruoyi.system.controller;

import java.util.List;
import io.swagger.annotations.*;
import com.ruoyi.common.core.domain.Response;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessTypeEnum;
import com.ruoyi.system.domain.WGood;
import com.ruoyi.system.service.IWGoodService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.ResponsePageInfo;

/**
 * 【物品】Controller
 *
 * @author ruoyi
 * @date 2022-01-06
 */
@RestController
@RequestMapping("/system/good")
@Api(tags={"【物品】Controller"})
public class WGoodController extends BaseController{
    @Autowired
    private IWGoodService wGoodService;

    /**
     * 查询物品列表
     */
    @PreAuthorize("@ss.hasPermi('system:good:list')")
    @GetMapping("/list")
    @ApiOperation("查询物品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<WGood> list(@ModelAttribute WGood wGood){
        startPage();
        List<WGood> list = wGoodService.selectWGoodList(wGood);
        return toResponsePageInfo(list);
    }

    /**
     * 导出物品列表
     */
    @PreAuthorize("@ss.hasPermi('system:good:export')")
    @Log(title = "物品", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出物品列表Excel")
    public Response<String> export(@ModelAttribute WGood wGood){
        List<WGood> list = wGoodService.selectWGoodList(wGood);
        ExcelUtil<WGood> util = new ExcelUtil<WGood>(WGood.class);
        return util.exportExcel(list, "good");
    }

    /**
     * 获取物品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:good:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取物品详细信息")
    public Response<WGood> getInfo(
            @ApiParam(name = "id", value = "物品参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(wGoodService.selectWGoodById(id));
    }

    /**
     * 新增物品
     */
    @PreAuthorize("@ss.hasPermi('system:good:add')")
    @Log(title = "物品", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增物品")
    public Response<Integer> add(@RequestBody WGood wGood){
        return toResponse(wGoodService.insertWGood(wGood));
    }

    /**
     * 修改物品
     */
    @PreAuthorize("@ss.hasPermi('system:good:edit')")
    @Log(title = "物品", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改物品")
    public Response<Integer> edit(@RequestBody WGood wGood){
        return toResponse(wGoodService.updateWGood(wGood));
    }

    /**
     * 删除物品
     */
    @PreAuthorize("@ss.hasPermi('system:good:remove')")
    @Log(title = "物品", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除物品")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "物品ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(wGoodService.deleteWGoodByIds(ids));
    }
}
